package com.baihao.provider;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 消息生产者
 *
 * @author: BaiHao
 * @date: 2020-03-11 下午 03:06
 */
@Component
public class TestProvider {

    @Autowired
    private RabbitTemplate rabbitTemplate;  //AmqpTemplate是一个接口，最终找到的实现类也就是RabbitTemplate，两个用起来没有区别

    @Value("${order.fanout.exchange}")
    private String exchange;

    @Value("${order.fanout.queue}")
    private String routeKey;

    public void sendMessage(Object object)
    {
        /*String orderId= UUID.randomUUID().toString().replace("-","");
        String message="你的订单号是:"+orderId+(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        Map<String,Object> map=new HashMap<>();
        map.put("orderId",orderId);
        map.put("date",new Date())*/
        System.out.println("消息生产者--------->"+object.toString()+"---"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss").format(new Date()));
        rabbitTemplate.convertAndSend(exchange,"order",object);
    }
}
